#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>

using namespace std;

class Solution {
public:
    string destCity(vector<vector<string>>& paths) {
        string dest;
        unordered_map<string, int> citySet;

        for (int row = 0; row < paths.size(); row++) {
            for (int colum = 0; colum < paths[row].size(); colum++) {
                CitySetProc(citySet, paths[row][colum], colum);
            }
        }

        // 最后只有两个地点存放到哈希中，找去其中的终点，就是最终行程的终点
        for (auto it = citySet.begin(); it!= citySet.end(); it++) {
            if (it->second == 1) {
                dest = it->first;
                break;
            }
        }
        return dest;
    }

    void CitySetProc(unordered_map<string, int> &citySet, const string city, int colum)
    {
        if (citySet.find(city) != citySet.end()) {
            citySet.erase(city);
            return;
        }

        if (colum == 0) {
            citySet[city] = -1; // 起点设置为-1
        } else {
            citySet[city] = 1; // 重终点设置为1
        }
        return;
    }
};

int main()
{
    Solution s;
    vector<vector<string>> path{{"pYyNGfBYbm","wxAscRuzOl"},{"kzwEQHfwce","pYyNGfBYbm"}};
    cout << s.destCity(path) << endl;

    return 0;
}